// Angular Version 6 below need to be deleted {providedIn: 'root'}

// angular
import {Injectable} from '@angular/core';
import {HttpParams} from '@angular/common/http';
// owner
import {Request} from 'pengesoft-ng-lib';
// models
// import {HttpServletRequest} from '../domains/httpservletrequest.domain';
import {PayRecordList} from '../domains/payrecordlist';
import {PayRecord} from '../domains/PayRecord';

/**
 * 
 */
@Injectable({
  providedIn: 'root'
})
export class PayRecordServiceSvr {
    private readonly baseUrl: string;

    constructor(
      private request: Request
    ) {
      this.baseUrl = 'PayRecordServiceSvr.assx/';
    }
  
    
    returnInfo(request: HttpParams): Promise<number> {
      const httpParams = new HttpParams()
        .append('request', request.toString());
      return this.request.post<number>(this.baseUrl + 'returnInfo', httpParams).then((res) => {
        return res;
      });
    }
  
    
    updatePaymentRecord(token: string, payRecordId: string, actualMoney: number, description: string, payWay: number): Promise<number> {
      const httpParams = new HttpParams()
        .append('token', token.toString())
        .append('payRecordId', payRecordId.toString())
        .append('actualMoney', actualMoney.toString())
        .append('description', description.toString())
        .append('payWay', payWay.toString());
      return this.request.post<number>(this.baseUrl + 'updatePaymentRecord', httpParams).then((res) => {
        return res;
      });
    }
  
    
    listPaymentRecord(token: string, status: number, customerId: string, customerName: string, houseId: string, startTime: Date, endTime: Date, isPostone: number, type: number, skip: number, size: number, option: number): Promise<PayRecordList> {
      const httpParams = new HttpParams()
        .append('token', token.toString())
        .append('status', status.toString())
        .append('customerId', customerId.toString())
        .append('customerName', customerName.toString())
        .append('houseId', houseId.toString())
        .append('startTime', startTime.toString())
        .append('endTime', endTime.toString())
        .append('isPostone', isPostone.toString())
        .append('type', type.toString())
        .append('skip', skip.toString())
        .append('size', size.toString())
        .append('option', option.toString());
      return this.request.post<PayRecordList>(this.baseUrl + 'listPaymentRecord', httpParams).then((res) => {
        return res
      });
    }
  
    
    GetVersion(): Promise<string> {
      const httpParams = new HttpParams();
      return this.request.post<string>(this.baseUrl + 'GetVersion', httpParams).then((res) => {
        return res;
      });
    }
  
    
    getPayInfo(token: string, customerId: string, contractId: string): Promise<PayRecord> {
      const httpParams = new HttpParams()
        .append('token', token.toString())
        .append('customerId', customerId.toString())
        .append('contractId', contractId.toString());
      return this.request.post<PayRecord>(this.baseUrl + 'getPayInfo', httpParams).then((res) => {
        return res
      });
    }
  
    
    pay(token: string, payRecordId: string, actualMoney: number, description: string, payWay: number): Promise<string> {
      const httpParams = new HttpParams()
        .append('token', token.toString())
        .append('payRecordId', payRecordId.toString())
        .append('actualMoney', actualMoney.toString())
        .append('description', description.toString())
        .append('payWay', payWay.toString());
      return this.request.post<string>(this.baseUrl + 'pay', httpParams).then((res) => {
        return res;
      });
    }
  
    
    getPaymentRecord(token: string, id: string): Promise<PayRecord> {
      const httpParams = new HttpParams()
        .append('token', token.toString())
        .append('id', id.toString());
      return this.request.post<PayRecord>(this.baseUrl + 'getPaymentRecord', httpParams).then((res) => {
        return res
      });
    }
  
    
    savePaymentRecord(token: string, contractId: string, type: number, repairApplyId: string, money: number): Promise<number> {
      const httpParams = new HttpParams()
        .append('token', token.toString())
        .append('contractId', contractId.toString())
        .append('type', type.toString())
        .append('repairApplyId', repairApplyId.toString())
        .append('money', money.toString());
      return this.request.post<number>(this.baseUrl + 'savePaymentRecord', httpParams).then((res) => {
        return res;
      });
    }
}
